﻿CREATE TABLE [dbo].[GamingSessionPlayer] (
    [GamingSessionPlayerId]   INT            IDENTITY (1, 1) NOT NULL,
    [GamingSessionId]          INT            NOT NULL,
    [BoardGamePlayerGroupId] INT            NOT NULL,
    [UserId]                    INT            NULL,
    [GuestName]                 NVARCHAR (32)  NULL,
    [CreatedBy]                 NVARCHAR (256) NOT NULL,
    [CreateDate]                DATETIME       NOT NULL,
    [ModifiedBy]                NVARCHAR (256) NOT NULL,
    [ModifyDate]                DATETIME       NOT NULL,
    CONSTRAINT [PK_GamingSessionPlayer] PRIMARY KEY CLUSTERED ([GamingSessionPlayerId] ASC),
    CONSTRAINT [FK_GamingSessionPlayer_IsOf_GamingSession] FOREIGN KEY ([GamingSessionId]) REFERENCES [dbo].[GamingSession] ([GamingSessionId]),
    CONSTRAINT [FK_GamingSessionPlayer_IsOf_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([UserId])
);


go
create unique index UX_GamingSessionPlayer_GamingSessionId_BoardGamePlayerGroupId_UserId_GuestName on GamingSessionPlayer (GamingSessionId,BoardGamePlayerGroupId,[UserId],GuestName)
go
create index IX_GamingSessionPlayer_GamingSessionId on GamingSessionPlayer (GamingSessionId)
go
create index IX_GamingSessionPlayer_UserId on GamingSessionPlayer ([UserId])
go
